home *** CD-ROM | disk | FTP | other *** search
- // LLIDview.cpp : implementation of the CLLIDView class
- //
-
- #include "stdafx.h"
-
- extern "C" // include the LightLibImage header file
- {
- #include "LLI.H"
- }
-
- #include "LLID.h"
- #include "LLIDdoc.h"
- #include "LLIDview.h"
-
- #include "math.h"
-
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CLLIDView
-
- IMPLEMENT_DYNCREATE(CLLIDView, CScrollView)
-
- BEGIN_MESSAGE_MAP(CLLIDView, CScrollView)
- //{{AFX_MSG_MAP(CLLIDView)
- ON_WM_PAINT()
- ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
- ON_COMMAND(ID_FIT_HOR, OnFitHor)
- ON_COMMAND(ID_FIT_WIN, OnFitWin)
- ON_COMMAND(ID_FIT_VER, OnFitVer)
- ON_COMMAND(ID_TOGGLE_PALETTE, OnTogglePalette)
- ON_COMMAND(ID_ROT_R90, OnRotR90)
- ON_COMMAND(ID_ROT_L90, OnRotL90)
- ON_COMMAND(ID_ROT_180, OnRot180)
- ON_WM_SIZE()
- ON_COMMAND(ID_UNFIT_WIN, OnUnfitWin)
- ON_COMMAND(ID_IMAGE_INFO, OnImageInfo)
- ON_COMMAND(ID_ZOOM_IN, OnZoomIn)
- ON_COMMAND(ID_ZOOM_OUT, OnZoomOut)
- ON_COMMAND(ID_CROP, OnCrop)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CLLIDView construction/destruction
-
- CLLIDView::CLLIDView()
- {
- // TODO: add construction code here
- }
-
- CLLIDView::~CLLIDView()
- {
- }
-
- void CLLIDView::OnDraw(CDC* pDC) // overridden to draw this view
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CLLIDView printing
-
- BOOL CLLIDView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CLLIDView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
-
- void CLLIDView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CLLIDView diagnostics
-
- #ifdef _DEBUG
- void CLLIDView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
-
- void CLLIDView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
-
- CLLIDDoc* CLLIDView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLLIDDoc)));
- return (CLLIDDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CLLIDView message handlers
-
-
- void CLLIDView::OnPaint()
- {
- CaptureAll();
-
- CPaintDC dc(this); // device context for painting
- CLLIDDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // we only paint the visible region of the image
-
- // get the size of the client area used for iPut
- CRect rect;
- GetClientRect( &rect );
-
- // get the current scrolloffset used for iPut
- CPoint ScrollOffset;
- ScrollOffset = GetScrollPosition();
-
- if( pDoc->lloImage )
- {
- DWORD pal;
- if ( ExclusivePaletteIsActive ) pal = LLI_PALETTE_EXCLUSIVE;
- else pal = LLI_PALETTE_SHARED;
-
- iPut( pDoc->lloImage, // pointer to the image
- ScrollOffset.x, // upper left corner X
- ScrollOffset.y, // upper left corner Y
- ScrollOffset.x + rect.Width(), // lower right corner X
- ScrollOffset.y + rect.Height(), // lower right corner Y
- LLI_SCREEN, // destination screen
- LLI_SCREEN_DEVICE_CONTEXT, // format
- 0, // horizontal offset on screen
- 0, // vertical offset on screen
- (DWORD)(dc.m_hDC), // devicecontext of this view
- pal, // palette shared or exclusive
- 0, // - not used -
- 0, // - not used -
- 0, // - not used -
- (DWORD)this ); // user parameter
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- // in case of an update first reset the capture region to the
- // entire size
- CaptureAll();
-
- CScrollView::OnUpdate(pSender, lHint, pHint);
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnInitialUpdate()
- {
- // initialize zoom state (100% from size cache)
- m_zoomNum = CSize(100, 100);
- m_zoomDenom = CSize(100, 100);
-
- // we need the imagesize in order to calculate the scrollsizes
- // of our view window.
- CLLIDDoc* pDoc = GetDocument();
- CSize dSize = pDoc->GetImageSize( TRUE );
- SetScrollSizes( MM_TEXT, dSize );
-
- CaptRect.left = 0; // and set CaptRect to this size
- CaptRect.top = 0;
- CaptRect.right = dSize.cx;
- CaptRect.bottom = dSize.cy;
- CaptureAll();
-
-
- ExclusivePaletteIsActive = FALSE;// for best image quality
- ScaleX = 1; ScaleY = 1; // initial scale in case of fit mode
-
- // initial zoomfactor for zoom in/out<<<
- ZoomX = -1;
- ZoomY = -1;
-
- rotangle = 0; // no rotation at the beginning
- CurrentFitMode = ID_UNFIT_WIN; // no fit mode at beginning
-
- // call base class last (will call OnUpdate)
- CScrollView::OnInitialUpdate();
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
- {
- CScrollView::OnPrepareDC(pDC, pInfo);
-
- pDC->SetMapMode(MM_TEXT);
- pDC->SetViewportExt(m_zoomNum);
- pDC->SetWindowExt(m_zoomDenom);
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- BOOL CLLIDView::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
- {
- CaptureAll();
- CRect rect;
- GetClientRect( &rect );
-
- // do the scroll
- if (!CScrollView::OnScrollBy(sizeScroll, bDoScroll))
- return FALSE;
-
- // update the position of the image
- if (bDoScroll)
- {
- UpdateWindow();
- }
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
-
- void CLLIDView::OnFilePrint()
- {
- // TODO: Add your command handler code here
- CPaintDC dc(this); // device context for painting
- CLLIDDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // get the current scrolloffset used for iPut
- CPoint ScrollOffset;
- ScrollOffset = GetScrollPosition();
-
- if( pDoc->lloImage )
- {
- if ( CaptureIsVisible ) // print the selectet area only
- {
- iPut(pDoc->lloImage, // pointer to the image
- ScrollOffset.x + CaptRect.left, // upper left corner X
- ScrollOffset.y + CaptRect.top, // upper left corner Y
- ScrollOffset.x + CaptRect.right, // lower right corner X
- ScrollOffset.y + CaptRect.bottom,// lower right corner Y
- LLI_PRINTER, // destination printer
- 0, // format
- 0, // horizontal printeroffset
- 0, // vertical printeroffset
- 0, // printer port
- 0, // density
- 0, // ejection
- 0, // page format
- 0, // - not used -
- (DWORD)this ); // userparameter
- }
- else // print the whole image
- {
- iPut(pDoc->lloImage, // pointer to the image
- 0, // upper left corner X
- 0, // upper left corner Y
- -1, // lower right corner X
- -1, // lower right corner Y
- LLI_PRINTER, // destination printer
- 0, // format
- 0, // horizontal printeroffset
- 0, // vertical printeroffset
- 0, // printer port
- 0, // density
- 0, // ejection
- 0, // page format
- 0, // - not used -
- (DWORD)this ); // userparameter
- }
- }
-
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::SwapInt(int *v1, int *v2)
- {
- int tmp; // swap two integer values
- tmp = *v1;
- *v1 = *v2;
- *v2 = tmp;
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::SwapFloat(float *v1, float *v2)
- {
- float tmp; // swap two float values
- tmp = *v1;
- *v1 = *v2;
- *v2 = tmp;
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- CRect CLLIDView::GetSelection()
- {
- // We return the selected region
- CRect Selection;
- CPoint ScrollOffset;
- ScrollOffset = GetScrollPosition();
-
- if ( CaptureIsVisible )
- {
- Selection.left = ScrollOffset.x + CaptRect.left;
- Selection.top = ScrollOffset.y + CaptRect.top;
- Selection.right = ScrollOffset.x + CaptRect.right;
- Selection.bottom = ScrollOffset.y + CaptRect.bottom;
- }
- else return CaptRect;
-
- return Selection;
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::CaptureAll()
- {
- if ( CaptureIsVisible ) // if the rectangle is allready visible then remove it
- { // before drawing the new one
- CDC *dc;
- dc = GetDC();
- dc->SelectObject( GetStockObject( NULL_BRUSH ) ); // hide the old frame
- dc->SetROP2( R2_NOTMERGEPEN );
- dc->Rectangle( CaptRect );
- ReleaseDC( dc );
- }
- CaptureIsVisible = FALSE;
- LButtonIsDown = 0;
- CLLIDDoc* pDoc = GetDocument(); // create a pointer to the image
- CSize si;
- si = pDoc->GetImageSize( TRUE ); // get height and width of image
- CaptRect.left = 0; // and set CaptRect to this size
- CaptRect.top = 0;
- CaptRect.right = si.cx;
- CaptRect.bottom = si.cy;
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- CLLIDDoc* pDoc = GetDocument();
- if ( !pDoc->lloImage ) return;
-
- // get height and width of current (not original) image
- CSize si;
- si = pDoc->GetImageSize( FALSE );
-
- CPoint ScrollOffset;
- ScrollOffset = GetScrollPosition();
-
- // capture inside picture only
- if ( ( point.x > ( si.cx - ScrollOffset.x ) ) ||
- ( point.y > ( si.cy - ScrollOffset.y ) ) ) return;
-
- CDC *dc;
- dc = GetDC();
-
- // if the rectangle is allready visible then remove it
- // before drawing the new one
- if ( CaptureIsVisible )
- {
- CaptureAll();
- }
-
- // Load new cursor and sve the old one
- oldCursor = SetCursor( LoadCursor( 0, IDC_CROSS ) );
-
- SetCapture(); // from now get all mouse input until LButtonUp
-
- CaptRect.left = point.x; // set CaptRect to the position where
- CaptRect.top = point.y; // the user clicked the left mousebutton
- CaptRect.right = point.x;
- CaptRect.bottom = point.y;
-
- LButtonIsDown = TRUE; // signal that the left button is pressed
-
- dc->SelectObject( GetStockObject( NULL_BRUSH ) );
- dc->SetROP2( R2_NOTMERGEPEN );
- dc->Rectangle( CaptRect );
-
- ReleaseDC(dc);
-
- CScrollView::OnLButtonDown(nFlags, point);
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- CLLIDDoc* pDoc = GetDocument();
- if ( !pDoc->lloImage ) return;
-
- // get height and width of current (not original) image
- CSize si;
- si = pDoc->GetImageSize( FALSE );
-
- CPoint ScrollOffset;
- ScrollOffset = GetScrollPosition();
-
-
- // don't leave the image area
- if ( point.x < 0 ) point.x = 0;
- if ( point.y < 0 ) point.y = 0;
- if ( ( point.x > ( si.cx - ScrollOffset.x ) ) )
- point.x = ( si.cx - ScrollOffset.x );
- if ( ( point.y > ( si.cy - ScrollOffset.y ) ) )
- point.y = ( si.cy - ScrollOffset.y );
-
- CDC *dc;
- dc = GetDC();
-
- if ( LButtonIsDown )
- {
- dc->SelectObject( GetStockObject( NULL_BRUSH ) );
- dc->SetROP2( R2_NOTMERGEPEN );
-
- dc->Rectangle( CaptRect );
-
- CaptRect.right = point.x;
- CaptRect.bottom = point.y;
-
- dc->Rectangle( CaptRect );
- }
-
- ReleaseDC( dc );
-
- CScrollView::OnMouseMove(nFlags, point);
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- if ( LButtonIsDown )
- {
- CLLIDDoc* pDoc = GetDocument();
- if ( !pDoc->lloImage ) return;
-
- // get height and width of current (not original) image
- CSize si;
- si = pDoc->GetImageSize( FALSE );
-
- CPoint ScrollOffset;
- ScrollOffset = GetScrollPosition();
-
- // only allow positions within the clientrect
- if ( point.x < 0 ) point.x = 0;
- if ( point.y < 0 ) point.y = 0;
- if ( ( point.x > ( si.cx - ScrollOffset.x ) ) )
- point.x = ( si.cx - ScrollOffset.x );
- if ( ( point.y > ( si.cy - ScrollOffset.y ) ) )
- point.y = ( si.cy - ScrollOffset.y );
-
- CaptRect.right = point.x;
- CaptRect.bottom = point.y;
- LButtonIsDown = FALSE;
-
- if ( (CaptRect.left != CaptRect.right) ||
- (CaptRect.top != CaptRect.bottom) )
- {
- CaptureIsVisible = TRUE;
- }
- else CaptureAll(); // set the capture region to maximum
-
- // retreive old cursor
- SetCursor ( oldCursor );
- }
-
- ReleaseCapture();
-
- if ( CaptRect.left > CaptRect.right )
- SwapInt(&CaptRect.left, &CaptRect.right);
-
- if ( CaptRect.top > CaptRect.bottom )
- SwapInt(&CaptRect.top, &CaptRect.bottom);
-
- CScrollView::OnLButtonUp(nFlags, point);
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
-
-
- void CLLIDView::OnFitHor()
- {
- // Fit the image to horizontal size of window
- // This mode is active until another fitmode or unfit is selected
- // When the window size changes, the image will be resized, too.
- Fit ( ID_FIT_HOR );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnFitVer()
- {
- // Fit the image to vertical size of window
- // This mode is active until another fitmode or unfit is selected
- // When the window size changes, the image will be resized, too.
- Fit ( ID_FIT_VER );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnFitWin()
- {
- // Fit the image to horizontal and vertical size of window
- // This mode is active until another fitmode or unfit is selected
- // When the window size changes, the image will be resized, too.
- Fit ( ID_FIT_WIN );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnUnfitWin()
- {
- // This function disables any of the fitmodes eventually selected
- // and restores the original image with its original size regardless
- // of the current windos clientrect size.
- Rotate( 0 );
- Fit ( ID_UNFIT_WIN );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::Fit( UINT fitmode )
- {
- CRect rect;
- GetClientRect( &rect );
-
- CLLIDDoc* pDoc = GetDocument();
- CSize DocSize = pDoc->GetImageSize( TRUE );
-
- if ( CaptureIsVisible )
- {
- DocSize.cx = CaptRect.Width();
- DocSize.cy = CaptRect.Height();
- }
-
- float zx,zy;
-
- switch ( fitmode )
- {
- case ID_FIT_VER :
- zy = -( (float)(rect.bottom) / (float)(DocSize.cy) );
- zx = zy;
- break;
-
- case ID_FIT_HOR :
- zx = -( (float)(rect.right) / (float)(DocSize.cx) );
- zy = zx;
- break;
-
- case ID_FIT_WIN :
- zx = -( (float)(rect.right) / (float)(DocSize.cx) );
- zy = -( (float)(rect.bottom) / (float)(DocSize.cy) );
- break;
-
- case ID_UNFIT_WIN :
- default :
- zx = -1;
- zy = -1;
- break;
-
- } // end switch ( fitmode )
-
- ZoomX = zx; // update the current zoomfactors used by Zoom In,Out
- ZoomY = zy;
-
- CurrentFitMode = fitmode;
-
- Zoom( zx, zy, FALSE );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::Zoom( float zfX, float zfY, BOOL crop )
- {
-
- float NewSizeX =0.0, NewSizeY = 0.0;
-
- // Load new cursor and sve the old one
- oldCursor = SetCursor( LoadCursor( 0, IDC_WAIT ) );
-
- CPaintDC dc(this); // device context for painting
- CLLIDDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // get the size of the client area used for iPut
- CRect rect;
- GetClientRect( &rect );
-
- // get the current scrolloffset used for zooming
- CPoint ScrollOffset;
- ScrollOffset = GetScrollPosition();
-
- CSize DocSize = pDoc->GetImageSize( TRUE );
-
- if ( zfX > 0 ) ScaleX *= zfX;
- else
- {
- if ( zfX < 0 ) ScaleX = (float)fabs( (double)zfX );
- else ScaleX = 1;
- }
-
- if ( zfY > 0 ) ScaleY *= zfY;
- else
- {
- if ( zfY < 0 ) ScaleY = (float)fabs( (double)zfY );
- else ScaleY = 1;
- }
-
- if( pDoc->lloImage )
- {
- if ( crop )
- {
-
-
- }
- else
- {
- if ( CaptureIsVisible ) // zoom the selected area only
- {
-
- NewSizeX = ( ScaleX * CaptRect.Width() );
- NewSizeY = ( ScaleY * CaptRect.Height() );
-
- IdleStart(20);
- pDoc->lloImage = iCopy( pDoc->lloImage, // pointer to the image
- ScrollOffset.x + CaptRect.left, // upper left corner X
- ScrollOffset.y + CaptRect.top, // upper left corner Y
- ScrollOffset.x + CaptRect.right, // lower right corner X
- ScrollOffset.y + CaptRect.bottom, // lower right corner Y
- LLI_COPY_ZOOM, // transformation mode
- (int)NewSizeX, // new horizontal size
- (int)NewSizeY, // new vertical size
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- (DWORD)this ); // userparameter
- IdleStop();
- }
- else // zoom the whole image
- {
- NewSizeX = (ScaleX * DocSize.cx);
- NewSizeY = (ScaleY * DocSize.cy);
-
- pDoc->lloImage = iCopy( pDoc->lloOrigImage, // pointer to image
- 0, // upper left corner X
- 0, // upper left corner Y
- DocSize.cx, // lower right corner X
- DocSize.cy, // lower right corner Y
- LLI_COPY_ZOOM, // transformation mode
- (int)NewSizeX, // new horizontal size
- (int)NewSizeY, // new vertical size
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- (DWORD)this ); // userparameter
- }
- }
-
- // update the scrolling size
- SetScrollSizes( MM_TEXT, pDoc->GetImageSize( FALSE ) );
- Invalidate( TRUE );
-
- }
- // retreive old cursor
- SetCursor ( oldCursor );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnTogglePalette()
- {
- // TODO: Add your command handler code here
-
-
- if ( ExclusivePaletteIsActive )
- ExclusivePaletteIsActive = FALSE;
- else
- ExclusivePaletteIsActive = TRUE;
-
- Invalidate( TRUE ); // now redraw with new palette
- UpdateWindow();
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnRotR90()
- {
- // rotate the image 90â–‘ to the right
- Rotate( 90 );
- SwapFloat( &ScaleX, &ScaleY );
- Fit( CurrentFitMode );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnRotL90()
- {
- // rotate the image 90â–‘ to the left
- Rotate( -90 );
- SwapFloat( &ScaleX, &ScaleY );
- Fit( CurrentFitMode );
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnRot180()
- {
- // rotate the image 180â–‘
- Rotate( 180 );
- Fit( CurrentFitMode );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::Rotate( int angle )
- {
- // Load new cursor and sve the old one
- oldCursor = SetCursor( LoadCursor( 0, IDC_WAIT ) );
-
- CPaintDC dc(this); // device context for painting
- CLLIDDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- if (angle == 0)
- {
- switch( rotangle )
- {
- case 90: angle = -90;
- break;
- case 180: angle = 180;
- break;
- case 270: angle = 90;
- break;
- default : angle = 0;
- break;
- }
- rotangle = 0;
- }
-
- if ( pDoc )
- {
- switch ( angle )
- {
- case 90:
- rotangle += 90;
- while (rotangle > 360) rotangle -= 360;
- IdleStart(20);
- pDoc->lloOrigImage = iCopy( pDoc->lloOrigImage,// pointer to image
- 0, // upper left corner X
- 0, // upper left corner Y
- -1, // lower right corner X
- -1, // lower right corner Y
- LLI_COPY_TURN, // transformation mode
- LLI_TURN_90, // rotation direction
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- (DWORD)this ); // userparameter
- IdleStop();
- break;
-
- case 180:
- rotangle += 180;
- while (rotangle > 360) rotangle -= 360;
- IdleStart(20);
- pDoc->lloOrigImage = iCopy( pDoc->lloOrigImage,// pointer to image
- 0, // upper left corner X
- 0, // upper left corner Y
- -1, // lower right corner X
- -1, // lower right corner Y
- LLI_COPY_TURN, // transformation mode
- LLI_TURN_180, // rotation direction
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- (DWORD)this ); // userparameter
- IdleStop();
- break;
-
- case -90:
- rotangle -= 90;
- while (rotangle < 0) rotangle += 360;
- IdleStart(20);
- pDoc->lloOrigImage = iCopy( pDoc->lloOrigImage,// pointer to image
- 0, // upper left corner X
- 0, // upper left corner Y
- -1, // lower right corner X
- -1, // lower right corner Y
- LLI_COPY_TURN, // transformation mode
- LLI_TURN_270, // rotation direction
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- (DWORD)this ); // userparameter
- IdleStop();
- break;
-
- default :; // do nothing
-
- } // end of switch
-
- // retreive old cursor
- SetCursor ( oldCursor );
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnSize(UINT nType, int cx, int cy)
- {
-
- switch ( CurrentFitMode )
- {
- case ID_FIT_HOR :
- case ID_FIT_VER :
- case ID_FIT_WIN : Fit( CurrentFitMode );
- break;
-
- case ID_UNFIT_WIN :
- Zoom( ZoomX, ZoomY, FALSE );
- break;
- default : ; // do nothing
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnImageInfo()
- {
- // TODO: Add your command handler code here
- AfxMessageBox( (LPCSTR)"Option not yet available");
-
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnZoomIn()
- {
-
- ZoomX += ((ZoomX/100)*10);
- ZoomY += ((ZoomY/100)*10);
-
- CurrentFitMode = ID_UNFIT_WIN;
-
- Zoom( ZoomX, ZoomY, FALSE );
-
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnZoomOut()
- {
-
- ZoomX -= ((ZoomX/100)*10);
- ZoomY -= ((ZoomY/100)*10);
-
- CurrentFitMode = ID_UNFIT_WIN;
-
- Zoom( ZoomX, ZoomY, FALSE );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::OnCrop()
- {
-
- CLLIDDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CPoint ScrollOffset;
- ScrollOffset = GetScrollPosition();
-
- IdleStart(20);
- pDoc->lloOrigImage = iCopy( pDoc->lloOrigImage, // pointer to the image
- (int)((float)(ScrollOffset.x + CaptRect.left) / ScaleX ), // upper left corner X
- (int)((float)(ScrollOffset.y + CaptRect.top) / ScaleY ), // upper left corner Y
- (int)((float)(ScrollOffset.x + CaptRect.right) / ScaleX ), // lower right corner X
- (int)((float)(ScrollOffset.y + CaptRect.bottom) / ScaleY ), // lower right corner Y
- LLI_COPY_CLONE, // transformation mode
- 0, // new horizontal size
- 0, // new vertical size
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- (DWORD)this ); // userparameter
- IdleStop();
- pDoc->lloImage = iCopy( pDoc->lloOrigImage, // pointer to the image
- 0, // upper left corner X
- 0, // upper left corner Y
- -1, // lower right corner X
- -1, // lower right corner Y
- LLI_COPY_CLONE, // transformation mode
- 0, // new horizontal size
- 0, // new vertical size
- 0, // not used in this case
- 0, // not used in this case
- 0, // not used in this case
- 0 ); // userparameter
-
- CaptureAll();
- Fit( ID_UNFIT_WIN );
-
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::IdleStart(int times)
- {
- oAssign( lloApp, LLI_APPLICATION_IDLE, (DWORD)OnIdle, times );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- void CLLIDView::IdleStop()
- {
- oAssign( lloApp, LLI_APPLICATION_IDLE, (DWORD)0, 0 );
- }
-
- /////////////////////////////////////////////////////////////////////////////////
-
- int EXPORTED OnIdle( DWORD dwType,
- LONG lParam,
- LLOBJECT pImage,
- DWORD dwAction,
- DWORD dwDevice,
- DWORD dwFormat,
- DWORD dwUdfParam )
- {
- //
- // 2nd try works, except the cancelbutton
- //
- //
- //
- //CLLIDView *pView = (CLLIDView *)(dwUdfParam);
-
- static RECT rect, bRect, emptyRect;
-
- char txt[20];
-
- static HWND hWnd;
- static HDC hDc;
- static HINSTANCE hInst;
-
- static HBRUSH BkGndBrush;
- static HBRUSH BarBrush;
- static HBRUSH EmptyBarBrush;
- static HBRUSH oldBrush;
-
- static HPEN cBkGndPen;
- static HPEN cBarPen;
- static HPEN cEmptyBarPen;
- static HPEN oldPen;
-
- // static CButton CancelButton;
- // #define IDB_CANCEL 111
-
- lParam *= 5;
- float slice = (float)(rect.right-10) / 100;
-
- switch (dwType)
- {
- case LLI_IDLE_INIT:
- hInst = AfxGetInstanceHandle();
-
- hWnd = CreateWindow( (LPCSTR)"EDIT",
- "working... please wait",
- WS_VISIBLE | WS_CAPTION,
- 200, 200, 250, 150,
- NULL ,
- NULL,
- hInst,
- NULL );
-
- ShowWindow( hWnd, SW_SHOW );
- UpdateWindow( hWnd );
-
- GetClientRect( hWnd, &rect );
-
- hDc = GetDC( hWnd );
-
- emptyRect.left = rect.left + 4;
- emptyRect.top = ((rect.bottom / 10) * 5 ) - 1;
- emptyRect.right = rect.right - 4;
- emptyRect.bottom = ((rect.bottom / 10) * 7) + 1;
-
-
- BkGndBrush = CreateSolidBrush( RGB(255, 255, 255) );
- oldBrush = (HBRUSH)SelectObject( hDc, BkGndBrush );
- cBkGndPen = CreatePen( PS_SOLID, 1, RGB(255, 255, 255) );
- oldPen = (HPEN)SelectObject( hDc, cBkGndPen );
- Rectangle( hDc, rect.left,
- rect.top,
- rect.right,
- rect.bottom);
-
- EmptyBarBrush = CreateSolidBrush( RGB(192, 192, 192) );
- SelectObject( hDc, EmptyBarBrush );
- cEmptyBarPen = CreatePen( PS_SOLID, 1, RGB(0, 0, 0) );
- SelectObject( hDc, cEmptyBarPen );
- Rectangle( hDc, emptyRect.left,
- emptyRect.top,
- emptyRect.right,
- emptyRect.bottom);
-
- BarBrush = CreateSolidBrush( RGB(0, 0, 255) );
- SelectObject( hDc, BarBrush );
- cBarPen = CreatePen( PS_SOLID, 1, RGB(255, 255, 255) );
- SelectObject( hDc, cBarPen );
-
- /*
- CancelButton.Create( "Cancel", // caption
- WS_CHILD | WS_VISIBLE,// style
- CRect(rect.left+10, // position and size
- rect.bottom-40, // -"-
- rect.right-10, // -"-
- rect.bottom-10),// -"-
- (CWnd *) hWnd, // parent
- IDB_CANCEL); // ID
-
- */
-
- break;
-
- case LLI_IDLE_IDLE:
- sprintf( txt, "%3d%% done ", (int)lParam );
- TextOut( hDc, rect.right / 2 - 30, 20, txt, strlen(txt) );
-
- bRect.left = 5;
- bRect.top = (rect.bottom / 10) * 5;
- bRect.right = (int)( 5 + (float)lParam * slice );
- bRect.bottom = (rect.bottom / 10) * 7;
-
- Rectangle( hDc, bRect.left,
- bRect.top,
- bRect.right,
- bRect.bottom);
- break;
-
- case LLI_IDLE_EXIT:
-
- SelectObject( hDc, oldBrush );
- SelectObject( hDc, oldPen );
-
- DeleteObject ( cEmptyBarPen );
- DeleteObject ( cBarPen );
- DeleteObject ( cBkGndPen );
-
- DeleteObject ( EmptyBarBrush );
- DeleteObject ( BarBrush );
- DeleteObject ( BkGndBrush );
-
- ReleaseDC( hWnd, hDc );
- DestroyWindow( hWnd );
- break;
-
- default:; // nothing
- }
-
- return ( TRUE );
-
-
- /*
-
- //<<< 3rd try >>>
-
- CLLIDView *pView = (CLLIDView *)(dwUdfParam);
-
- #define IDB_CANCEL 111
- #define IDW_PERCENT_DLG 112
-
- static CWnd PercentDlg;
-
- static CRect rect, bRect, emptyRect;
-
- char txt[20];
-
- static CDC *dc;
-
- static CBrush *BkGndBrush;
- static CBrush *BarBrush;
- static CBrush *EmptyBarBrush;
- static CBrush *oldBrush;
-
- static CPen *cBkGndPen;
- static CPen *cBarPen;
- static CPen *cEmptyBarPen;
- static CPen *oldPen;
- static float slice;
- static CButton CancelButton;
-
- lParam *= 5;
-
- switch (dwType)
- {
- case LLI_IDLE_INIT:
- PercentDlg.Create((LPCSTR)"EDIT",
- "working... please wait",
- WS_VISIBLE | WS_CAPTION,
- CRect(200, 200, 250, 150),
- (CWnd *)HWND_DESKTOP, //parent
- IDW_PERCENT_DLG,
- NULL );
-
- PercentDlg.ShowWindow( SW_SHOW );
- PercentDlg.UpdateWindow();
-
- dc = PercentDlg.GetDC();
- PercentDlg.GetClientRect( &rect );
- slice = (float)(rect.right-4) / 100;
-
- BkGndBrush = new CBrush();
- BarBrush = new CBrush();
- EmptyBarBrush = new CBrush();
-
- cBkGndPen = new CPen;
- cBarPen = new CPen;
- cEmptyBarPen = new CPen;
-
- emptyRect.left = rect.left + 1;
- emptyRect.top = ((rect.bottom / 10) * 4 ) - 1;
- emptyRect.right = rect.right - 1;
- emptyRect.bottom = ((rect.bottom / 10) * 6) + 1;
-
-
- BkGndBrush->CreateSolidBrush( RGB(255, 255, 255) );
- oldBrush = dc->SelectObject( BkGndBrush );
- cBkGndPen->CreatePen( PS_SOLID, 1, RGB(255, 255, 255) );
- oldPen = dc->SelectObject( cBkGndPen );
- dc->Rectangle( rect );
-
- EmptyBarBrush->CreateSolidBrush( RGB(192, 192, 192) );
- dc->SelectObject( EmptyBarBrush );
- cEmptyBarPen->CreatePen( PS_SOLID, 1, RGB(0, 0, 0) );
- dc->SelectObject( cEmptyBarPen );
- dc->Rectangle( emptyRect );
-
- BarBrush->CreateSolidBrush( RGB(0, 0, 255) );
- dc->SelectObject( BarBrush );
- cBarPen->CreatePen( PS_SOLID, 1, RGB(255, 255, 255) );
- dc->SelectObject( cBarPen );
-
- CancelButton.Create( "Cancel",
- WS_CHILD | WS_VISIBLE,
- CRect(rect.left+10,
- rect.bottom-40,
- rect.right-10,
- rect.bottom-10),
- (CWnd *) &PercentDlg,
- IDB_CANCEL);
-
- break;
-
- case LLI_IDLE_IDLE:
- sprintf( txt, "%3d%% done ", (int)lParam );
- dc->TextOut( rect.right / 2 - 30, 0, txt, strlen(txt) );
-
- bRect.left = 2;
- bRect.top = (rect.bottom / 10) * 4;
- bRect.right = (int)( 2 + (float)lParam * slice );
- bRect.bottom = (rect.bottom / 10) * 6;
-
- dc->Rectangle( bRect );
- break;
-
- case LLI_IDLE_EXIT:
-
- dc->SelectObject( oldBrush );
- dc->SelectObject( oldPen );
-
- delete ( cEmptyBarPen );
- delete ( cBarPen );
- delete ( cBkGndPen );
-
- delete ( EmptyBarBrush );
- delete ( BarBrush );
- delete ( BkGndBrush );
-
- PercentDlg.ReleaseDC( dc );
- PercentDlg.DestroyWindow();
- break;
-
- default:; // nothing
- }
-
- return ( TRUE );
-
- */
-
- /*
- // <<< this original works !!! >>>
-
- CLLIDView *pView = (CLLIDView *)(dwUdfParam);
-
- CRect rect, bRect, emptyRect;
- pView->GetClientRect( &rect );
-
- char txt[20];
-
- static CDC *dc;
-
- static CBrush *BkGndBrush;
- static CBrush *BarBrush;
- static CBrush *EmptyBarBrush;
- static CBrush *oldBrush;
-
- static CPen *cBkGndPen;
- static CPen *cBarPen;
- static CPen *cEmptyBarPen;
- static CPen *oldPen;
-
- lParam *= 5;
- float slice = (float)(rect.right-4) / 100;
-
- switch (dwType)
- {
- case LLI_IDLE_INIT:
-
- dc = pView->GetDC();
-
- BkGndBrush = new CBrush();
- BarBrush = new CBrush();
- EmptyBarBrush = new CBrush();
-
- cBkGndPen = new CPen;
- cBarPen = new CPen;
- cEmptyBarPen = new CPen;
-
- emptyRect.left = rect.left + 1;
- emptyRect.top = ((rect.bottom / 10) * 4 ) - 1;
- emptyRect.right = rect.right - 1;
- emptyRect.bottom = ((rect.bottom / 10) * 6) + 1;
-
-
- BkGndBrush->CreateSolidBrush( RGB(255, 255, 255) );
- oldBrush = dc->SelectObject( BkGndBrush );
- cBkGndPen->CreatePen( PS_SOLID, 1, RGB(255, 255, 255) );
- oldPen = dc->SelectObject( cBkGndPen );
- dc->Rectangle( rect );
-
- EmptyBarBrush->CreateSolidBrush( RGB(192, 192, 192) );
- dc->SelectObject( EmptyBarBrush );
- cEmptyBarPen->CreatePen( PS_SOLID, 1, RGB(0, 0, 0) );
- dc->SelectObject( cEmptyBarPen );
- dc->Rectangle( emptyRect );
-
- BarBrush->CreateSolidBrush( RGB(0, 0, 255) );
- dc->SelectObject( BarBrush );
- cBarPen->CreatePen( PS_SOLID, 1, RGB(255, 255, 255) );
- dc->SelectObject( cBarPen );
- break;
-
- case LLI_IDLE_IDLE:
- sprintf( txt, "%3d%% done ", (int)lParam );
- dc->TextOut( rect.right / 2 - 30, 0, txt, strlen(txt) );
-
- bRect.left = 2;
- bRect.top = (rect.bottom / 10) * 4;
- bRect.right = (int)( 2 + (float)lParam * slice );
- bRect.bottom = (rect.bottom / 10) * 6;
-
- dc->Rectangle( bRect );
- break;
-
- case LLI_IDLE_EXIT:
-
- dc->SelectObject( oldBrush );
- dc->SelectObject( oldPen );
-
- delete ( cEmptyBarPen );
- delete ( cBarPen );
- delete ( cBkGndPen );
-
- delete ( EmptyBarBrush );
- delete ( BarBrush );
- delete ( BkGndBrush );
-
- pView->ReleaseDC( dc );
- break;
-
- default:; // nothing
- }
-
- return ( TRUE );
-
- */
-
- }
-
-
-